package main

import (
    "my_git_repos/gointro/pipeline"
    "fmt"
    "os"
    "bufio"
)

func main()  {
    const filename = "large.in"
    const n = 1000000
    file, err := os.Create(filename)
    if err != nil {
        panic(err)
    }

    defer file.Close()

    p := pipeline.RandomSource(n)
    writer := bufio.NewWriter(file)
    pipeline.WriteSink(writer, p)
    writer.Flush()

    //file ,err = os.Open(filename)
    //if err != nil {
    //    panic(err)
    //}
    //defer file.Close()
    //
    //reader := bufio.NewReader(file)
    //p = pipeline.ReaderSource(reader, -1)
    //
    //count := 0
    //for v := range p {
    //    if v != 0 {
    //        count++
    //    }
    //}
    //fmt.Println(count)
}
func mergeDemo() {
    p := pipeline.Merge(
        pipeline.InMemSort(pipeline.ArraySource(1, 9 ,5, 1, 10)),
        pipeline.InMemSort(pipeline.ArraySource(100, 6 ,8, 35, 10)),
    )
    for v := range p {
        fmt.Println(v)
    }
}
